package vista;

import java.awt.Color;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTextField;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;

public class Pantalla extends JTextField {
    
    public Pantalla()
    {
        setCaretColor(Color.blue);
        setColumns(40);
    }
    
    public void anadirTexto(String texto) {
        int indice = getCaretPosition();
        try {
            Document documento = getDocument();
            documento.insertString(indice, texto, null);
        } catch (BadLocationException ex) {
            Logger.getLogger(Pantalla.class.getName()).log(Level.SEVERE, null, ex);
        }
        indice += texto.length();
    }
    
    public void quitarTexto(int indice, int tamanio) {
        try {
            Document documento = getDocument();
            documento.remove(indice, tamanio);
        } catch (BadLocationException ex) {
            Logger.getLogger(Pantalla.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
